$(function() {
})
function submit() {
	var money = $('#money').val();
	if (isNaN(money)) {
		$.alert("请输入正确的数字");
		return;
	}
	if(money<=0){
		$.alert("必须为正数");
		return;
	}
	if(Math.floor(money*100)!=money*100){
		$.alert("只能有2位小数");
		return;
	}
	if (money * 100 > $('#purse').val()) {
		$.alert("没有足够的钱来提现");
		return;
	}
	if ($('#payPass').val().length < 1) {
		$.alert("请输入支付密码");
		return;
	}
	if ($("input[type='radio']:checked").val() == null) {
		$.alert("请选择银行卡");
		return;
	}
	showLoading();
	$.ajax({
		url : appPath + '/money/saveWithdrawalsOrder.json',
		dataType : 'json',
		type : 'post',
		data : {
			token : $.cookie("token"),
			money : money*100,
			payPass : $.md5($('#payPass').val() + $('#key').val()),
			bankcardId : $("input[type='radio']:checked").val()
		},
		success : function(data) {
			hideLoading();
			if (data.code == -1) {
				myalert("请登录", function() {
					window.location.href = appPath + "/member/login.htm";
				})
				return;
			}
			if (data.code == 0) {
				myalert(data.msg);
				return;
			} else {
				myalert(data.msg, function() {
					gotoHtml('/center/center.htm');
				});
			}
		},
		error : function() {
			hideLoading();
			myalert("系统异常，请重试");
		}
	})
}

function editBankcard(id) {
	gotoHtml('/bankcard/bankcard.htm?bankcardId='+id);
}

function deleteBankcard(id) {
	myconfirm("确定要删除吗？", function() {
		showLoading();
		$.ajax({
			url : appPath + "/bankcard/deleteBankcard.json",
			dataType : 'json',
			type : 'post',
			data : {
				token : $.cookie("token"),
				bankcardId : id
			},
			success : function(data) {
				hideLoading();
				if (data.code == -1) {
					myalert("请登录", function() {
						window.location = appPath + "/member/login.htm";
					})
					return;
				}
				if (data.code == 0) {
					myalert(data.msg);
					return;
				} else {
					myalert(data.msg);
				    $('#'+id).remove();
				    $('#num').text( $('#num').text()-1);
				}
			},
			error : function() {
				hideLoading();
				myalert("系统异常，请重试");
			}
		})
	})
}

function defaultBankcard(id) {
	showLoading();
	$.ajax({
		url : appPath + "/bankcard/defaultBankcard.json",
		dataType : 'json',
		type : 'post',
		data : {
			token : $.cookie("token"),
			bankcardId : id
		},
		success : function(data) {
			hideLoading();
			if (data.code == "-1") {
				$.alert("请登录", function() {
					window.location = appPath + "/member/login.html";
				})
				return;
			}
			if (data.code == "0") {
				myalert(data.msg);
				return;
			} else {
				myalert(data.msg, function() {
					window.location.reload();
				})
			}
		},
		error : function() {
			hideLoading();
			myalert("系统异常，请重试");
		}
	})
}
